FROM m.daocloud.io/docker.io/library/python:3.9-slim

# 配置APT源
RUN apt-get update && \
    apt-get install -y apt-transport-https ca-certificates && \
    echo "deb https://mirrors.ustc.edu.cn/debian/ $(grep -oP 'VERSION_CODENAME=\K\w+' /etc/os-release) main contrib non-free" > /etc/apt/sources.list && \
    echo "deb https://mirrors.ustc.edu.cn/debian/ $(grep -oP 'VERSION_CODENAME=\K\w+' /etc/os-release)-updates main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb https://mirrors.ustc.edu.cn/debian-security/ $(grep -oP 'VERSION_CODENAME=\K\w+' /etc/os-release)-security main contrib non-free" >> /etc/apt/sources.list

# 安装LibreOffice和必要的依赖
RUN apt-get update && apt-get install -y \
    libreoffice \
    libreoffice-writer \
    --no-install-recommends \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# 设置pip镜像源 - 直接创建配置文件
RUN mkdir -p /root/.pip && \
    echo "[global]" > /root/.pip/pip.conf && \
    echo "index-url = https://pypi.tuna.tsinghua.edu.cn/simple" >> /root/.pip/pip.conf && \
    echo "trusted-host = pypi.tuna.tsinghua.edu.cn" >> /root/.pip/pip.conf

# 创建工作目录
WORKDIR /app

# 先复制requirements.txt并安装依赖，利用Docker缓存机制
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# 复制Python脚本到容器
COPY libreofficeDockerCall.py /app/
COPY main.py /app/

# 创建输入、输出和临时目录
RUN mkdir -p /app/input /app/output /app/temp

# 确保目录权限正确
RUN chmod -R 777 /app/input /app/output /app/temp

# 设置环境变量
ENV PYTHONUNBUFFERED=1

# 暴露API端口
EXPOSE 8001

# 启动命令 - 只启动FastAPI应用，因为我们不再使用LibreOffice Online
CMD ["python", "/app/main.py"] 